import { Product } from '@/modules/businessModule/product/assets/product.entity';
import { Seat } from '@/modules/businessModule/seat/assets/seat.entity';
import { ApiProperty } from '@nestjs/swagger';
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class Good {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  @ApiProperty({ description: '账户' })
  account: string;

  @Column()
  @ApiProperty({ description: '密码' })
  password: string;

  @Column({ nullable: true, type: 'bigint' })
  @ApiProperty({ type: 'bigint', description: '账号结束时间' })
  goodEndTime: number;

  @Column({ default: 0 })
  @ApiProperty({ default: 0, description: '座位数' })
  seatsNum: number;

  @Column({ type: 'bigint', default: Date.now() })
  @ApiProperty({ default: 'Date.now()', type: 'bigint', description: '账号开始时间' })
  goodStartTime: number;

  @CreateDateColumn({
    type: 'datetime',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP(0)',
    onUpdate: 'CURRENT_TIMESTAMP(0)',
  })
  createTime: Date;

  @ApiProperty({ description: '产品', type: () => Product })
  @ManyToOne(() => Product, (product) => product.good)
  product: Product;

  @ApiProperty({ description: '座位', type: () => Seat })
  @OneToMany(() => Seat, (seat) => seat.good)
  seats: Seat[];
}
